/*
 * @Description: 响应请求错误
 * @Author: liushuang
 * @Date: 2022-03-23 15:57:06
 * @LastEditTime: 2022-07-08 16:31:50
 */

const requestError = (error) => {
  let message = ''
  if (error && error.response) {
    switch (error.response.status) {
      case 400:
        message = '请求错误'
        break
      case 401:
        message = '未授权，请登录'
        break
      case 403:
        message = '拒绝访问'
        break
      case 404:
        message = `请求地址出错: ${error.response.config.url}`
        break
      case 408:
        message = '请求超时'
        break
      case 500:
        message = '服务器内部错误'
        break
      case 501:
        message = '服务未实现'
        break
      case 502:
        message = '网关错误'
        break
      case 503:
        message = '服务不可用'
        break
      case 504:
        message = '网关超时'
        break
      case 505:
        message = 'HTTP版本不受支持'
        break
      default:
        message = '请求失败'
        break
    }
  } else if (error.message === 'Network Error') {
    message = '请求失败，请检查您的网络设置'
  }
  return message
}

export default requestError
